package com.nineclock.approve.nodeResolver;

import cn.hutool.json.JSONObject;
import com.nineclock.common.utils.ActivitiUtils;
import com.nineclock.common.utils.UUIDUtils;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.SequenceFlow;

/**
 * 流程节点抽象类
 */
public abstract class ProcessNodeResolver {

    /**
     * 添加节点到流程Process中
     *
     * @param process
     * @param currNode
     * @param nextNode
     */
    public abstract void addFlowNodeToActiviti(Process process, JSONObject currNode, JSONObject nextNode);

    /**
     * 获取当前节点的Key/ID
     *
     * @param currNode
     * @return
     */
    protected String getNodeId(JSONObject currNode) {
        String type = currNode.getStr("type");
        String nodekey = currNode.getStr("nodeKey");
        return ActivitiUtils.getKey(type, nodekey);
    }


    protected void addSequenceFlowToActiviti(Process process, JSONObject currNode , JSONObject nextNode){
        //绘制连线节点
        SequenceFlow sf = new SequenceFlow();
        sf.setId("seq_"+UUIDUtils.getUUID());
        sf.setSourceRef(getNodeId(currNode));
        sf.setTargetRef(getNodeId(nextNode));

        process.addFlowElement(sf);
    }

}